Using the light nodes

Use the light nodes to create sources of light for a Scene in your Kanzi application.

Kanzi has these light node types:

Lights contain properties that are passed as uniforms to shaders when Kanzi renders 3D objects. Note that lights affect only the rendering of objects which use materials with shaders that use those lights. For example, spot lights work only with the materials that support spot lights in the shaders. In Kanzi these material types in <KanziInstallation>/Studio/Asset Library/MaterialTypes/General support two spot lights by default:

If you want to use more or different lights, you have to modify the shaders. See Editing shaders.

Creating a light node

To create a light node:

  1. In the Project press Alt and right-click the node where you want to create a light node and select Directional Light, Point Light, or Spot Light.
    Note that you create light nodes only inside Scene and 3D nodes.
  2. In the Preview Edit mode use the Node tool to position the light node.
  3. In the Properties adjust the properties of the light node to create the light suitable for your needs.
    For example, adjust the color of the light.

Using the light nodes in the API

To create and set a directional light:

// Create a directional light named Directional light.
LightSharedPtr directionalLight = Light::createDirectional(domain, "Directional light");
// Rotate the directional light node by -45 degrees around the x axis.
directionalLight->rotate(-45.0f, 1.0f, 0.0f, 0.0f);
// Set the color of the directional light to red.
directionalLight->setDirectionalLightColor(KanziThemeRed);

To create and set a point light:

// Create a point light named Point light.
LightSharedPtr pointLight = Light::createPoint(domain, "Point light");
// Move the point light on y axis by 4 units.
pointLight->setTranslation(0.0f, 4.0f, 0.0f);
// Set the color of the point light to green.
pointLight->setPointLightColor(KanziThemeGreen);
// Set the constant attenuation for the point light to 0.8, and linear and quadratic attenuation to 0.
pointLight->setPointLightAttenuation(Vector3(0.8f, 0.0f, 0.0f));

To create and set a spot light:

// Create a spot light named Spot light.
LightSharedPtr spotLight = Light::createSpot(domain, "Spot light");
// Move the spot light on x axis by 4 units.
spotLight->setTranslation(4.0f, 0.0f, 0.0f);
// Rotate the spot light around the y axis by 90 degrees.
spotLight->rotate(90.0f, 0.0f, 1.0f, 0.0f);
// Set the color of the spot light to blue.
spotLight->setSpotLightColor(KanziThemeBlue);
// Set the angle of the spot light cone to 45 degrees.
spotLight->setSpotLightCutoffAngle(45.0f);
// Set how concentrated the spot light is. TODO What's the range? Can you describe what kind of spot light value 30 makes?
spotLight->setSpotLightExponent(30.0f);
// Set the constant attenuation for the spot light to 1.3, and linear and quadratic attenuation to 0.
spotLight->setSpotLightAttenuation(Vector3(1.3f, 0.0f, 0.0f));

See also

Shaders

Editing shaders